"""
 -*- coding: utf-8-*-
 @File: api_base.py
 @Author: chen
 @time: 2023/12/01/ 19:52
"""
import os

import requests

from stage_L1.lim_project.api_po.utils.mgt_logger import logger
from stage_L1.lim_project.api_po.utils.mgt_yaml import YamlMgt

cur_path = os.path.dirname(os.path.abspath(__file__))
env_file = os.path.join(cur_path, "./config/env_info.yaml")
env_data = YamlMgt.read(env_file)


class BaseApi:
    _host = env_data["test_host"]
    headers = env_data["headers"]
    payload = {}

    def send(self, method, path, **kwargs):
        """
        :param method: 请求的方法，如get，post，delete，put等
        :param path: 请求路径
        :param kwargs: 请求参数
        :return:
        """
        url = "".join([self._host, path])
        logger.info(f"{method}接口【{url}】的请求体：{self.payload}")
        resp = requests.request(method, url, headers=self.headers, verify=False, timeout=5, **kwargs)
        logger.info(f"{method}接口【{url}】的响应码：{resp.status_code}")
        logger.info(f"{method}接口【{url}】的响应体：{resp.text}")
        self.payload = {}
        return resp
